﻿using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Iprojects.Forms;
using System.IO;
using System.Configuration;


namespace Iprojects
{
    public partial class MainForm : Form
    {

        
        #region subforms

        private Forms.FormLogin frmAbout;
        private Forms.FamilyPersonAdd frmPersonAdd;
        private Forms.ProjectFamilymastora frmProjectFamily;
        private Forms.ProjectFoodBoxes frmProjectFoodBoxes;
        private Forms.ProjectSchoolBags frmProjectSchoolBags;
        private Forms.ProjecHomeFixes frmProjecHomeFixes;
        private Forms.ReportByDateAndProject frmReportByDateAndProject;
        private Forms.ReportByIDAndProject frmReportByIDAndProject;
        private Forms.Projec_SearchByName frmProjec_SearchByName;


        
        private Forms.ReportMasrofatByDateAndProject frmReportMasrofatByDateAndProject;
         private Forms.ReportPhoneByFamily frmReportPhoneByFamily;
        
        #endregion

        #region CTOR
        public MainForm()
        {
            InitializeComponent();
        }
       
        #endregion
        #region Try ICon Notify Events
       

        #endregion
        #region control events

        protected override void OnClosed(EventArgs e)
        {
            base.OnClosed(e);
            ImportGISFiles();


        }

        private void aboutSharePointTipsUtilityPackToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            ImportGISFiles();
        }
        public void ImportGISFiles()
        {

            string sourcePath = ConfigurationManager.AppSettings["DbFilepath"];
            string destinationPath = ConfigurationManager.AppSettings["BackUpFilepath"];
            //   string BackUpdestinationFolder = ConfigurationManager.AppSettings["BackUpFilepath"];
            string destinationFolder = "bak" + DateTime.Now.ToString("dd_MM_yyyy");
         //   ImportGISFiles(DbFilepath, BackUpFilepath, "bak" + DateTime.Now.ToString("dd_mm_yyy"));
            string fileName = string.Empty;
            fileName = Path.GetFileName(sourcePath);
            string fullbackupfilepath =destinationPath + "\\" + destinationFolder + "\\" +DateTime.Now.ToString("dd_MM_yyyy")+"_"+ fileName ;
           
            if (!Directory.Exists(destinationPath + destinationFolder))
                Directory.CreateDirectory(destinationPath + "\\" + destinationFolder);
             //   Directory.Delete(destinationPath + destinationFolder, true);
           
            //string[] fileArray = Directory.GetFiles(sourcePath);


            if (File.Exists(fullbackupfilepath))
            {
                fullbackupfilepath = destinationPath + "\\" + destinationFolder + "\\" + DateTime.Now.ToString("dd_MM_yyyy--hh--mm") + "_" + fileName;
                if (File.Exists(fullbackupfilepath))
                {
                    return;
                }
                else
                {
                    File.Copy(sourcePath, fullbackupfilepath);
                }
                
            }
            else {
                File.Copy(sourcePath, fullbackupfilepath);
            }
            
        }


        

        

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (this.frmPersonAdd != null) this.frmPersonAdd.Close();
       
         
                this.frmPersonAdd = new Forms.FamilyPersonAdd();
            
            this.ShowForm(this.frmPersonAdd);
        }

        private void toolStripStatusLabel1_Click(object sender, EventArgs e)
        {
            try
            {
                //Please don't change this
                Process process1 = new Process();
                process1.StartInfo.FileName = "iexplore.exe";
                process1.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;
                process1.StartInfo.Arguments = "www.3akka.com";
                process1.Start();
            }
            catch (Exception exception1)
            {
                MessageBox.Show("Could not open the browser: '" + exception1.Message + "'" + Environment.NewLine + " Please visit me at www.spstips.blogspot.com", "Error opening web site", MessageBoxButtons.OK);
            }

        }
        
        #endregion 

        #region custom code

        private void ShowForm(Form frm)
        {
            frm.MdiParent = this;
            frm.Show();
        }

        #endregion


        #region Menu Event
        private void startCrawlerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if ((this.frmProjectFamily == null) || this.frmProjectFamily.IsDisposed)
            {
                this.frmProjectFamily = new ProjectFamilymastora();
            }
            this.ShowForm(this.frmProjectFamily);

        }

        private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
        {

            if ((this.frmProjectFoodBoxes == null) || this.frmProjectFoodBoxes.IsDisposed)
            {
                this.frmProjectFoodBoxes = new ProjectFoodBoxes();
            }
            this.ShowForm(this.frmProjectFoodBoxes);

            //ShowSettings(-1);
        }

        void ShowSettings(int nSelectedIndex)
        {
            //if ((this.frmCrawler == null) || this.frmCrawler.IsDisposed)
            //{
            //frmCrawler=new CrawlerForm();
            //}
            //SettingsForm form = new SettingsForm();
            //form.SelectedIndex = nSelectedIndex;
            //this.ShowForm(form);
            
            //    frmCrawler.ThreadCount = Settings.GetValue("Threads count", 10);
            //   frmCrawler.InitValues();
               
              
            
        }

        private void mimeTypesToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if ((this.frmProjectSchoolBags == null) || this.frmProjectSchoolBags.IsDisposed)
            {
                this.frmProjectSchoolBags = new ProjectSchoolBags();
            }
            this.ShowForm(this.frmProjectSchoolBags);
        }

        private void outputToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if ((this.frmProjecHomeFixes == null) || this.frmProjecHomeFixes.IsDisposed)
            {
                this.frmProjecHomeFixes = new ProjecHomeFixes();
            }
            this.ShowForm(this.frmProjecHomeFixes);
            
        }

        private void connectionsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowSettings(2);
        }

        private void advancedToolStripMenuItem_Click(object sender, EventArgs e)
        {
            ShowSettings(3);
        }

        private void startPublisherToolStripMenuItem_Click(object sender, EventArgs e)
        {

            if ((this.frmReportByDateAndProject == null) || this.frmReportByDateAndProject.IsDisposed)
            {
                this.frmReportByDateAndProject = new ReportByDateAndProject();
            }
            this.ShowForm(this.frmReportByDateAndProject);
        }

        private void spiderToolStripMenuItem1_Click(object sender, EventArgs e)
        {
            if ((this.frmReportMasrofatByDateAndProject == null) || this.frmReportMasrofatByDateAndProject.IsDisposed)
            {
                this.frmReportMasrofatByDateAndProject = new ReportMasrofatByDateAndProject();
            }
            this.ShowForm(this.frmReportMasrofatByDateAndProject);

        }

        private void publishToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //if ((this.frmPublish == null) || this.frmPublish.IsDisposed)
            //{
            //    this.frmPublish = new Publisher();
            //}
            //this.ShowForm(this.frmPublish);
            
        }
    #endregion

        private void تقريرالعائلةToolStripMenuItem_Click(object sender, EventArgs e)
        {


            if ((this.frmReportByIDAndProject == null) || this.frmReportByIDAndProject.IsDisposed)
            {
                this.frmReportByIDAndProject = new ReportByIDAndProject();
            }
            this.ShowForm(this.frmReportByIDAndProject);
        }

        private void قائمةالعائلاتToolStripMenuItem_Click(object sender, EventArgs e)
        {
            

                 if ((this.frmReportPhoneByFamily == null) || this.frmReportPhoneByFamily.IsDisposed)
            {
                this.frmReportPhoneByFamily = new ReportPhoneByFamily();
            }
            this.ShowForm(this.frmReportPhoneByFamily);
        
        }

        private void بحثToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //todo 
            if ((this.frmProjec_SearchByName == null) || this.frmProjec_SearchByName.IsDisposed)
            {
                this.frmProjec_SearchByName = new Projec_SearchByName();
            }
            this.ShowForm(this.frmProjec_SearchByName);
            
            
        }

       

        
        


    }
}